package com.example.demo.leetcode.classics150;

import java.util.*;

/**
 * ******************************************************
 *
 * @author liugh9
 * @version 1.0
 * @classname _43字母异位词分组
 * @description
 * @date 2023/07/22 9:16
 * <p>
 * ******************************************************
 */
public class _43字母异位词分组 {

    public List<List<String>> groupAnagrams(String[] strs) {
        Map<String, List<String>> map = new HashMap<>();

        for (String str : strs) {
            char[] chars = str.toCharArray();
            Arrays.sort(chars);
            String s = Arrays.toString(chars);
            List<String> item = map.getOrDefault(s, new LinkedList<>());
            item.add(str);
            map.put(s, item);
        }

        return new LinkedList<>(map.values());
    }
}
